package com.bjpowernode.app;

import javafx.scene.Parent;

import java.io.File;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Set;

//文件被占用无法删除
//文件夹里面有子无法删除
//文件存在无法创建
//文件夹存在无法创建
//删除文件或者文件夹：file.delete()
//创建文件夹：file.mkdir()、file.mkdirs()
//创建文件：file.createNewFile()
public class MyApp5 {
    private LinkedList linkedList = new LinkedList();

    public void all(HashMap hashMap) {
        Set set = hashMap.keySet();
        for (Object setTemp : set) {
            Object o = hashMap.get(setTemp);
            String path = root;
            if (o instanceof HashMap) {
                linkedList.add(setTemp);
                for (Object o1 : linkedList) {
                    path += "\\" + o1;
                }
                File file = new File(path);
                boolean mkdir = file.mkdirs();
                if (mkdir) {
                    System.out.println(path + ":创建成功...");
                } else {
                    System.out.println(path + ":创建失败************************");
                }
                all((HashMap) o);
            } else {
                linkedList.pollLast();
            }
        }


    }

    String root = "d:\\web1";

    public String getRoot() {
        return root;
    }

    public void setRoot(String root) {
        this.root = root;
    }

    public static void main(String[] args) {

        //利用HashMap创建层次结构
        HashMap hashMapWeb = new HashMap();
        HashMap hashMapSrc = new HashMap();
        HashMap hashMapMain = new HashMap();
        HashMap hashMapTest = new HashMap();
        HashMap hashMapJava = new HashMap();
        HashMap hashMapCom = new HashMap();
        HashMap hashMapBjpowernode = new HashMap();
        HashMap hashMapBeans = new HashMap();
        HashMap hashMapMapper = new HashMap();
        HashMap hashMapServices = new HashMap();
        HashMap hashMapController = new HashMap();
        HashMap hashMapResources = new HashMap();

        hashMapResources.put("resources", "resources");
        hashMapMapper.put("mapper", "mapper");
        hashMapServices.put("services", "services");
        hashMapController.put("controller", "controller");
        hashMapBeans.put("beans", "beans");
        hashMapBjpowernode.put("beans", hashMapBeans);
        hashMapBjpowernode.put("services", hashMapServices);
        hashMapBjpowernode.put("controller", hashMapController);
        hashMapBjpowernode.put("mapper", hashMapMapper);
        hashMapCom.put("bjpowernode", hashMapBjpowernode);
        hashMapJava.put("com", hashMapCom);
        hashMapTest.put("test", "test");
        hashMapMain.put("java", hashMapJava);
        hashMapMain.put("resources", hashMapResources);
        hashMapSrc.put("main", hashMapMain);
        hashMapSrc.put("test", hashMapTest);
        hashMapWeb.put("src", hashMapSrc);
        MyApp5 myApp5 = new MyApp5();
        //利用递归创建目录
        myApp5.all(hashMapWeb);
    }
}